home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / news / misc / newsxd-2.5.1-shar / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-08  |  5.3 KB  |  155 lines

  1. /*
  2.  * #include <legal/bs.h>
  3.  >
  4.  > Copyright (c) 1989 Washington University in Saint Louis, Missouri and
  5.  > Chris Myers. All rights reserved.
  6.  >
  7.  > Permission is hereby granted to copy, reproduce, redistribute or
  8.  > otherwise use this software as long as: (1) there is no monetary
  9.  > profit gained specifically from the use or reproduction of this
  10.  > software, (2) it is not sold, rented, traded, or otherwise marketed,
  11.  > (3) the above copyright notice and this paragraph is included
  12.  > prominently in any copy made, and (4) that the name of the University
  13.  > is not used to endorse or promote products derived from this software
  14.  > without the specific prior written permission of the University.
  15.  > THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  > IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  > WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  >
  19.  */
  20.  
  21. #include "defs.h"
  22.  
  23. /*************************************************************************/
  24. /* FUNCTION  : log                                                       */
  25. /* PURPOSE   : Log messages to syslog or a log file, as defined in       */
  26. /*             newsxd.h.  If debug or DEBUG is set, log to stderr.       */
  27. /* ARGUMENTS : Log priority, message to log, and message parameters      */
  28. /*************************************************************************/
  29.  
  30. void
  31. log(priority, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) /*VARARGS2*/
  32.     int  priority;
  33.     char *message, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
  34.  
  35. {
  36. static  FILE    *logfile = NULL;
  37. long    clock;
  38. extern  int     errno;
  39. char    buffer[30];
  40.  
  41.    if ((debug > 0) || (DEBUG > 0)) {
  42.       (void) fprintf(stderr, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  43.       return;
  44.    }
  45.  
  46. #if     defined(SYSLOG)
  47.    syslog(priority, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  48. #endif
  49.  
  50. #if     defined(FAKESYSLOG)
  51.    if ((logfile != NULL) && (CONFIGCHANGEDFILE)) {
  52.        (void) fclose(logfile);
  53.        logfile = NULL;
  54.        CONFIGCHANGEDFILE = 0;
  55.    }
  56.    if (logfile == NULL) {
  57.       logfile = fopen(fakelogfile, "a");
  58.    }
  59.  
  60.    if (logfile != NULL) {
  61.       (void) time(&clock);
  62.       (void) strcpy(buffer, ctime(&clock));
  63.       *index(buffer, '\n') = ' ';
  64.       (void) fputs(buffer, logfile);
  65.       (void) fprintf(logfile, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  66.       (void) fflush(logfile);
  67.    }
  68. #endif
  69.  
  70. }
  71.  
  72. /*************************************************************************/
  73. /* FUNCTION  : logerr                                                    */
  74. /* PURPOSE   : Log an error to syslog                                    */
  75. /* ARGUMENTS : Message to log, and message parameters                    */
  76. /*************************************************************************/
  77.  
  78. void
  79. logerr(message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) /*VARARGS1*/
  80.     char *message, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
  81.  
  82. {
  83.  
  84.    log(LOG_ERR, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  85.  
  86. }
  87.  
  88. /*************************************************************************/
  89. /* FUNCTION  : Dprintf                                                   */
  90. /* PURPOSE   : Do COPIOUS debugging logging                              */
  91. /* ARGUMENTS : Message to log, and message parameters                    */
  92. /*************************************************************************/
  93.  
  94. void
  95. Dprintf(message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) /*VARARGS1*/
  96.     char *message, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
  97.  
  98. {
  99.  
  100.    if (DEBUG != 0)
  101.       log(LOG_DEBUG, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  102.  
  103. }
  104.  
  105. /*************************************************************************/
  106. /* FUNCTION  : dprintf                                                   */
  107. /* PURPOSE   : Do normal debugging logging                               */
  108. /* ARGUMENTS : Message to log, and message parameters                    */
  109. /*************************************************************************/
  110.  
  111. void
  112. dprintf(message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) /*VARARGS1*/
  113.     char *message, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
  114.  
  115. {
  116.  
  117.    if (debug != 0)
  118.       log(LOG_DEBUG, message, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
  119.  
  120. }
  121.  
  122. /*************************************************************************/
  123. /* FUNCTION  : debug_off                                                 */
  124. /* PURPOSE   : Increase debugging level during program execution         */
  125. /* ARGUMENTS : none                                                      */
  126. /*************************************************************************/
  127.  
  128. void
  129. debug_on()
  130.  
  131. {
  132.  
  133.    if (debug) DEBUG = -1; else debug = -1;
  134.    log(LOG_INFO, "Debugging changed to debug %s, DEBUG %s\n",
  135.       debug ? "On" : "Off", DEBUG ? "On" : "Off");
  136.  
  137. }
  138.  
  139. /*************************************************************************/
  140. /* FUNCTION  : debug_off                                                 */
  141. /* PURPOSE   : Reduce debugging level during program execution           */
  142. /* ARGUMENTS : none                                                      */
  143. /*************************************************************************/
  144.  
  145. void
  146. debug_off()
  147.  
  148. {
  149.  
  150.    if (DEBUG) DEBUG = 0; else debug = 0;
  151.    log(LOG_INFO, "Debugging changed to debug %s, DEBUG %s\n",
  152.       debug ? "On" : "Off", DEBUG ? "On" : "Off");
  153.  
  154. }
  155.